import pymysql

# 数据库连接
db = pymysql.connect(
    host="localhost",
    user="root",
    password="123123",
    port=3306,
    database="db_jxgl",
)


cursor = db.cursor()

#SQL语句
sql = 'select * from tb_class'

#执行sql
execute = cursor.execute(sql)
print(execute)

all = cursor.fetchall()
print(all[1])


#提交，增删改等操作需要执行
# db.commit()

#获取数据
# one = cursor.fetchone()    #获取1条数据
# many = cursor.fetchmany()   #获取指定条数数据，不填默认为1
# all = cursor.fetchall()    #获取全部数据
# print(one)
# print(all)

#关闭游标
cursor.close()
#关闭数据库hh
db.close()